package com.pulanit.pangu.admin.web.controller.business;

import com.pulanit.pangu.admin.business.api.entity.ArticleEdit;
import com.pulanit.pangu.admin.business.api.service.IArticleEditService;
import cn.hutool.core.lang.Assert;
import com.gitee.pulanos.pangu.framework.sdk.dto.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 文稿编辑关联表 前端控制器
 * </p>
 *
 * @author 天鸣
 * @since 2024-03-06
 */
@RestController
@RequestMapping("/api/business/articleEdit")
public class ArticleEditController {

    @Autowired
    private IArticleEditService articleEditService;

    /**
    * 获取列表
    *
    * @return
    */
    @GetMapping("/list")
    public Result<List<ArticleEdit>> list() {
       List<ArticleEdit> list = articleEditService.list();
       return Result.success(list);
    }

    /**
     * 获取详情
     * @return
     */
    @GetMapping("/detail")
    public Result<ArticleEdit> detail(@RequestParam("id") Long id){
        Assert.notNull(id, "ID 不能为空");
        ArticleEdit articleEdit = articleEditService.getById(id);
        return Result.success(articleEdit);
    }

    /**
     * 保存
     * @param articleEdit
     * @return
     */
    @PostMapping("/add")
    public Result<Void> add(@RequestBody ArticleEdit articleEdit){
        articleEditService.save(articleEdit);
        return Result.success();
    }

    /**
     * 修改
     * @param articleEdit
     * @return
     */
    @PostMapping("/update")
    public Result<Void> update(@RequestBody ArticleEdit articleEdit){
        articleEditService.updateById(articleEdit);
        return Result.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public Result<Void> delete(@RequestParam("id") Long id){
        Assert.notNull(id, "ID 不能为空");
        articleEditService.removeById(id);
        return Result.success();
    }

    /**
     * 批量删除
     *
     */
     @PostMapping("/batchDelete")
     public Result<Void> batchDelete(@RequestParam List<Long> ids) {
        Assert.notEmpty(ids, "ID 不能为空");
        articleEditService.removeBatchByIds(ids);
        return Result.success();
     }

}
